#include <iostream>
#include <string>
#include <vector>

using namespace std;

// 检查数组是否为回文数
bool is_palindrome(const vector<int>& a) {
    int len = a.size();
    for (int i = 0; i < len / 2; i++) {
        if (a[i] != a[len - i - 1]) return false;
    }
    return true;
}

// 计算两个N进制数的和
void add_numbers(const vector<int>& a, const vector<int>& b, vector<int>& result, int n) {
    int carry = 0;
    result.clear();
    int max_len = max(a.size(), b.size());

    for (int i = 0; i < max_len || carry; i++) {
        int sum = carry;
        if (i < a.size()) sum += a[i];
        if (i < b.size()) sum += b[i];
        result.push_back(sum % n);
        carry = sum / n;
    }
}

// 将数字转换为N进制数组
vector<int> convert_to_base(const string& str, int n) {
    vector<int> result;
    for (char c : str) {
        if (c >= '0' && c <= '9') {
            result.push_back(c - '0');
        } else if (c >= 'A' && c <= 'F') {
            result.push_back(c - 'A' + 10);
        }
    }
    return result;
}

// 转换N进制数组为字符串（用于输出）
string base_to_string(const vector<int>& num, int n) {
    string result;
    for (auto it = num.rbegin(); it != num.rend(); ++it) {
        if (*it < 10) {
            result += ('0' + *it);
        } else {
            result += ('A' + (*it - 10));
        }
    }
    return result;
}

int main() {
    int n;
    string m;
    cin >> n >> m;

    vector<int> number = convert_to_base(m, n);
    int steps = 0;

    while (!is_palindrome(number) && steps <= 30) {
        vector<int> reversed(number.rbegin(), number.rend());
        vector<int> sum;

        add_numbers(number, reversed, sum, n);
        number = sum;
        steps++;
    }

    if (steps <= 30) {
        cout << steps << endl;
    } else {
        cout << "Impossible" << endl;
    }

    return 0;
}